package net.wanho.controller;


import net.wanho.po.Dept;
import net.wanho.service.DeptService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.wanho.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import lombok.RequiredArgsConstructor;



import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author 汤小洋
 * @since 2023-08-18
 */
@Api(tags = "部门表接口")
@RestController
@RequestMapping("/dept")
@RequiredArgsConstructor
public class DeptController {

    private final DeptService deptService;

    @ApiOperation("部门表分页查询")
    @GetMapping("/list")
    public AjaxResult findPage(@ApiParam("页码") @RequestParam(defaultValue = "1") int pagenum,@ApiParam("页大小") @RequestParam(defaultValue = "5") int pagesize,@ApiParam("查询条件") Dept dept){
        PageInfo<Dept> pageInfo = deptService.findPage(pagenum,pagesize,dept);
        return AjaxResult.success(pageInfo);
    }

    @ApiOperation("根据主键查询部门表")
    @GetMapping("/{id}")
    public AjaxResult findById(@PathVariable Serializable id){
        return AjaxResult.success(deptService.findById(id));
    }

    @ApiOperation("新增部门表")
    @PostMapping
    public AjaxResult add(@RequestBody Dept dept){
        deptService.add(dept);
        return AjaxResult.success();
    }

    @ApiOperation("修改部门表")
    @PutMapping
    public AjaxResult modify(@RequestBody Dept dept){
        deptService.modify(dept);
        return AjaxResult.success();
    }

    @ApiOperation("根据主键删除部门表")
    @DeleteMapping("/{id}")
    public AjaxResult removeById(@PathVariable Serializable id){
        deptService.removeById(id);
        return AjaxResult.success();
    }

}
